namespace 项目01
{
    class Student
    {
        public string name;
        public string id;
        public string gender;
        private int age;

        public int Age
        {
            get => age;
            set
            {
                if (value < 0 || value > 150) age = 0;
                else age = value;
            }
        }
        public Phone phone;

        public string GitInfo()
        {
            return $"姓名:{name}\n 身份证:{id}\n 年龄:{age}\n 性别:{gender}\n 手机型号:{phone.型号}\n 手机号码:{phone.号码}\n";
        }

        public Student(string 姓名, string 学号, string 手机型号, string 手机号码)
        {
            name = 姓名;
            id = 学号;
            获取身份证信息();
            phone = new Phone(姓名, 手机型号, 手机号码);

        }

        // public (string 性别, int 年龄) 获取身份证信息()
        // {
        //     int 身份证倒数第二位 = id[16];
        //     gender = 身份证倒数第二位 % 2 == 0 ? "女" : "男";
        //     DateTime today = DateTime.Now;
        //     string year = id[6..10];
        //     string month = id[10..12];
        //     string day = id[12..14];
        //     DateTime birhday = DateTime.Parse($"{year}-{month}-{day}");
        //     int age = today.Year - birhday.Year;
        //     if (today.Month > birhday.Month) age--;
        //     if (today.Month == birhday.Month && today.Day < birhday.Day) age--;
        //     return (gender, age);
        // }

        public void 获取身份证信息()
        {
            int 身份证倒数第二位 = id[16];
            gender = 身份证倒数第二位 % 2 == 0 ? "女" : "男";
            DateTime today = DateTime.Now;
            string year = id[6..10];
            string month = id[10..12];
            string day = id[12..14];
            DateTime birhday = DateTime.Parse($"{year}-{month}-{day}");
            Age = today.Year - birhday.Year;
            if (today.Month < birhday.Month) Age--;
            if (today.Month == birhday.Month && today.Day < birhday.Day) Age--;
        }
    }
}